package com.wanggsx.library.base.view;

import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import com.google.android.material.navigation.NavigationView;
import androidx.drawerlayout.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.widget.FrameLayout;

import com.wanggsx.library.R;
import com.wanggsx.library.util.UtilsActivity;
import com.wanggsx.library.util.UtilsString;

/**
 * ```
 * author: wanggsx
 * blog  : http://blog.csdn.net/wanggsx918
 * time  : 2018/11/16
 * desc  : base about drawer activity
 * ```
 */
public abstract class BaseDrawerActivity extends BaseActivity {

    protected DrawerLayout mDrawerRootLayout;
    protected FrameLayout mDrawerContainerView;

    @Override
    public int setRootLayoutId() {
        super.setContentView(R.layout.activity_drawer);
        int layoutId = setRootLayout1();
        FrameLayout drawerContainerView = findViewById(R.id.drawerContainerView);
        if (layoutId > 0) {
            LayoutInflater.from(this).inflate(layoutId, drawerContainerView);
        }
        NavigationView drawerNavView  = findViewById(R.id.drawerNavView);
        drawerNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//                if (item.getItemId() == R.id.action_git_hub){
//                    return goWeb(R.string.github);
//                }else if(item.getItemId() == R.id.action_blog){
//                    return goWeb(R.string.blog);
//                }
                return false;
            }
        });
        mDrawerRootLayout = findViewById(R.id.drawerRootLayout);
        mDrawerContainerView = drawerContainerView;
        return -1;
    }

    public abstract int setRootLayout1();

    private boolean goWeb(int id){
        return UtilsActivity.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse(UtilsString.getString(id)))
        );
    }
}
